//
//  DownloadProgressView.swift
//  SwiftUIAnimation
//
//  Created by 李煜 on 2024/8/20.
//

import SwiftUI

struct DownloadProgressView: View {
  @State private var isLoading = false
  var body: some View {
    ZStack {
      Text("loading")
        .font(.system(size: 50, design: .rounded))
        .bold()
        .offset(x: 10.0, y: -50)
      RoundedRectangle(cornerRadius: 3)
        .stroke(Color(.systemGray5),lineWidth: 3)
        .frame(width: 250, height: 3)

      RoundedRectangle(cornerRadius: 3)
        .stroke(.green, lineWidth: 3)
        .frame(width: 30, height: 3)
        .offset(x: isLoading ? 110 : -110, y: 0)
        .animation(.linear(duration: 1).repeatForever(autoreverses: false), value: isLoading)
    }
    .onAppear {
      isLoading = true
    }
  }
}

#Preview {
  DownloadProgressView()
}
